/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.aaron.platform.service;

import com.aaron.platform.exceptions.RoleAlreadyExistException;
import com.aaron.platform.exceptions.RoleNotExistException;
import com.aaron.platform.exceptions.RoleUserExistException;
import com.aaron.platform.exceptions.XmlParseException;
import com.aaron.platform.exceptions.XmlPathException;
import com.aaron.platform.entity.ItscPriInfo;
import com.aaron.platform.entity.ItscRoleInfo;
import com.aaron.platform.entity.ItscUserInfo;
import java.util.List;

/**
 *
 * @author chenzhuohua
 */
public interface IAuthorityService {

    /**
     * the init funtion after creating the instance
     * @throws XmlPathException
     * @throws XmlParseException
     */
    public void init() throws XmlPathException, XmlParseException;

    /**
     * find a role by ID
     * @param roleId role ID
     * @return role entity
     * @throws RoleNotExistException
     */
    public ItscRoleInfo findRoleById(Integer roleId) throws RoleNotExistException;

    /**
     * find a role by unique name
     * @param roleName role name
     * @return role entity
     * @throws RoleNotExistException
     */
    public ItscRoleInfo findRoleByName(String roleName) throws RoleNotExistException;

    /**
     * find all roles
     * @return role list
     */
    public List<ItscRoleInfo> findAllRoles();

    /**
     * add a new role
     * @param roleInfo the new role information
     * @throws RoleAlreadyExistException
     */
    public void addRole(ItscRoleInfo roleInfo) throws RoleAlreadyExistException;

    /**
     * update a role information
     * @param roleInfo 
     * @throws RoleAlreadyExistException
     * @throws RoleNotExistException
     */
    public void updateRole(ItscRoleInfo roleInfo) 
            throws RoleAlreadyExistException, RoleNotExistException;

    /**
     * remove a role. You can't romove it if it is referenced by a user
     * @param roleId role ID
     * @throws RoleNotExistException
     * @throws RoleUserExistException
     */
    public void removeRole(Integer roleId)
            throws RoleNotExistException, RoleUserExistException;

    /**
     * 设置角色的权限信息，先删除再添加
     * @param roleId 角色ID
     * @param priInfos 权限列表
     * @throws RoleNotExistException
     */
    public void updateRolePrivilege(Integer roleId, List<ItscPriInfo> priInfos) throws RoleNotExistException;

    /**
     * whether has this privilege
     * @param userInfo user information
     * @param previlegeName the name of privilege
     * @return
     */
    public boolean hasPrivilege(ItscUserInfo userInfo, String privilegeName);

    /**
     * whether has extension the priviege
     * @param userInfo user information
     * @param privilegeName the name of privilege
     * @param extName extention operation of privilege
     * @return
     */
    public boolean hasExtPrivilege(ItscUserInfo userInfo, String privilegeName, String extName);

    /**
     * whether has this privilege
     * @param roleId role ID
     * @param previlegeName the name of privilege
     * @return
     */
    public boolean hasPrivilege(Integer roleId, String privilegeName);

    /**
     * whether has extension the priviege
     * @param Integer role Id
     * @param privilegeName the name of privilege
     * @param extName extention operation of privilege
     * @return
     */
    public boolean hasExtPrivilege(Integer roleId, String privilegeName, String extName);

    /**
     * find the all privileges of a user
     * @param userId
     * @return
     */
    public List<ItscPriInfo> findUserPrivileges(ItscUserInfo userInfo);

    /**
     * 查询角色的所有权限信息
     * @param roleId 角色ID
     * @return 权限列表
     */
    public List<ItscPriInfo> findRolePrivileges(Integer roleId);

}
